<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //现有字符串如下 name1与value1为一组参数信息,每一组使用&符号拼接起来的 name1表示为参数名value1表示为值  
        var search = '?name1=value1&name2=value2';
        // 封装一个函数可以获取到指定参数的值
        function getUrlParam(key, search) {
            var result = '';
            search.substr(1).split('&').forEach(function (item, index) {
                let keyValue = item.split('=');
                if (key == keyValue[0]) {
                    result = keyValue[1];
                }
            })
            return result;
        }

        var res = getUrlParam('name2', search); //value1
        console.log(res);
    </script>
</body>

</html>